//
//  WSShowFilterConditionView.m
//  microvision
//
//  Created by zhenjingxiong on 2021/3/10.
//  Copyright © 2021 tencent. All rights reserved.
//

#import "WSShowFilterConditionView.h"
#import "WSDataReportHelper.h"

@interface WSShowFilterConditionView ()

@property (nonatomic, strong) UITextView *textView;

@end

@implementation WSShowFilterConditionView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (UITextView *)textView {
    if (!_textView) {
        _textView = [UITextView new];
        _textView.text = @"暂无过滤条件";
        _textView.userInteractionEnabled = NO;
    }
    return _textView;
}

- (void)setupUI {
    self.backgroundColor = [UIColor yellowColor];
    
    UILabel *label = [UILabel new];
    label.text = @"筛选条件如下";
    
    [self addSubview:label];
    label.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint *layoutConstraintLeading = [WSDataReportHelper equallyRelatedConstraintWithView:label toItem:self attribute:NSLayoutAttributeLeading];
    NSLayoutConstraint *layoutConstraintTop = [WSDataReportHelper equallyRelatedConstraintWithView:label toItem:self attribute:NSLayoutAttributeTop];
    [self addConstraints:@[layoutConstraintLeading, layoutConstraintTop]];

    [self addSubview:self.textView];
    self.textView.translatesAutoresizingMaskIntoConstraints = NO;
    NSLayoutConstraint *textViewLayoutConstraintLeading = [WSDataReportHelper equallyRelatedConstraintWithView:self.textView toItem:self attribute:NSLayoutAttributeLeading];
    NSLayoutConstraint *textViewLayoutConstraintRight = [WSDataReportHelper equallyRelatedConstraintWithView:self.textView toItem:self attribute:NSLayoutAttributeRight];
    NSLayoutConstraint *textViewLayoutConstraintBottom = [WSDataReportHelper equallyRelatedConstraintWithView:self.textView toItem:self attribute:NSLayoutAttributeBottom];
    NSLayoutConstraint *textViewLayoutConstraintTop = [NSLayoutConstraint constraintWithItem:self.textView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:label attribute:NSLayoutAttributeBottom multiplier:1.0 constant:2];
    [self addConstraints:@[textViewLayoutConstraintLeading, textViewLayoutConstraintRight, textViewLayoutConstraintBottom, textViewLayoutConstraintTop]];
}


- (void)updateFilterConditionViewContent:(NSString *)filterContent {
    if (filterContent) {
        self.textView.text = (filterContent.length ? filterContent : @"暂无过滤条件") ;
    }
}

@end
